]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st/theme-context: Expose accent color
authorAlice Mikhaylenko <alicem@gnome.org>
Tue, 21 Mar 2023 19:00:15 +0000 (23:00 +0400)
committerMarge Bot <marge-bot@gnome.org>
Thu, 20 Jun 2024 13:18:00 +0000 (13:18 +0000)
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2715>

src/st/st-theme-context.c
src/st/st-theme-context.h

index 4055786d629b2e19881fd0bda7e3f36c5be0c4b8..865ab6125d788df3b673d239dedd73a2fc559f8d 100644 (file)
 #include "st-theme-context.h"
 #include "st-theme-node-private.h"
 
+#define ACCENT_COLOR_BLUE   "#3584e4"
+#define ACCENT_COLOR_TEAL   "#2190a4"
+#define ACCENT_COLOR_GREEN  "#3a944a"
+#define ACCENT_COLOR_YELLOW "#c88800"
+#define ACCENT_COLOR_ORANGE "#ed5b00"
+#define ACCENT_COLOR_RED    "#e62d42"
+#define ACCENT_COLOR_PINK   "#d56199"
+#define ACCENT_COLOR_PURPLE "#9141ac"
+#define ACCENT_COLOR_SLATE  "#6f8396"
+
+#define ACCENT_FG_COLOR     "#ffffff"
+
 struct _StThemeContext {
   GObject parent;
 
   PangoFontDescription *font;
+  CoglColor accent_color;
+  CoglColor accent_fg_color;
+
   StThemeNode *root_node;
   StTheme *theme;
 
@@ -68,6 +83,7 @@ static PangoFontDescription *get_interface_font_description (void);
 static void on_font_name_changed (StSettings     *settings,
                                   GParamSpec     *pspec,
                                   StThemeContext *context);
+static void update_accent_colors (StThemeContext *context);
 static void on_icon_theme_changed (StTextureCache *cache,
                                    StThemeContext *context);
 static void st_theme_context_changed (StThemeContext *context);
@@ -102,6 +118,9 @@ st_theme_context_finalize (GObject *object)
   g_signal_handlers_disconnect_by_func (st_settings_get (),
                                         (gpointer) on_font_name_changed,
                                         context);
+  g_signal_handlers_disconnect_by_func (st_settings_get (),
+                                        (gpointer) update_accent_colors,
+                                        context);
   g_signal_handlers_disconnect_by_func (st_texture_cache_get_default (),
                                        (gpointer) on_icon_theme_changed,
                                        context);
@@ -171,6 +190,10 @@ st_theme_context_init (StThemeContext *context)
                     "notify::font-name",
                     G_CALLBACK (on_font_name_changed),
                     context);
+  g_signal_connect_swapped (st_settings_get (),
+                            "notify::accent-color",
+                            G_CALLBACK (update_accent_colors),
+                            context);
   g_signal_connect (st_texture_cache_get_default (),
                     "icon-theme-changed",
                     G_CALLBACK (on_icon_theme_changed),
@@ -184,6 +207,8 @@ st_theme_context_init (StThemeContext *context)
                                           (GEqualFunc) st_theme_node_equal,
                                           g_object_unref, NULL);
   context->scale_factor = 1;
+
+  update_accent_colors (context);
 }
 
 static void
@@ -254,6 +279,61 @@ get_interface_font_description (void)
   return pango_font_description_from_string (font_name);
 }
 
+static void
+update_accent_colors (StThemeContext *context)
+{
+  StSettings *settings = st_settings_get ();
+  StSystemAccentColor accent_color;
+
+  g_object_get (settings, "accent-color", &accent_color, NULL);
+
+  switch (accent_color)
+    {
+    case ST_SYSTEM_ACCENT_COLOR_BLUE:
+      cogl_color_from_string (&context->accent_color, ACCENT_COLOR_BLUE);
+      break;
+
+    case ST_SYSTEM_ACCENT_COLOR_TEAL:
+      cogl_color_from_string (&context->accent_color, ACCENT_COLOR_TEAL);
+      break;
+
+    case ST_SYSTEM_ACCENT_COLOR_GREEN:
+      cogl_color_from_string (&context->accent_color, ACCENT_COLOR_GREEN);
+      break;
+
+    case ST_SYSTEM_ACCENT_COLOR_YELLOW:
+      cogl_color_from_string (&context->accent_color, ACCENT_COLOR_YELLOW);
+      break;
+
+    case ST_SYSTEM_ACCENT_COLOR_ORANGE:
+      cogl_color_from_string (&context->accent_color, ACCENT_COLOR_ORANGE);
+      break;
+
+    case ST_SYSTEM_ACCENT_COLOR_RED:
+      cogl_color_from_string (&context->accent_color, ACCENT_COLOR_RED);
+      break;
+
+    case ST_SYSTEM_ACCENT_COLOR_PINK:
+      cogl_color_from_string (&context->accent_color, ACCENT_COLOR_PINK);
+      break;
+
+    case ST_SYSTEM_ACCENT_COLOR_PURPLE:
+      cogl_color_from_string (&context->accent_color, ACCENT_COLOR_PURPLE);
+      break;
+
+    case ST_SYSTEM_ACCENT_COLOR_SLATE:
+      cogl_color_from_string (&context->accent_color, ACCENT_COLOR_SLATE);
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
+
+  cogl_color_from_string (&context->accent_fg_color, ACCENT_FG_COLOR);
+
+  st_theme_context_changed (context);
+}
+
 static void
 on_stage_destroy (ClutterStage *stage)
 {
@@ -431,6 +511,28 @@ st_theme_context_get_font (StThemeContext *context)
   return context->font;
 }
 
+/**
+ * st_theme_context_get_accent_color:
+ * @context: a #StThemeContext
+ * @color: (out) (nullable): the accent color
+ * @fg_color: (out) (nullable): the foreground accent color
+ *
+ * Gets the current accent color for the theme context.
+ */
+void
+st_theme_context_get_accent_color (StThemeContext *context,
+                                   CoglColor      *color,
+                                   CoglColor      *fg_color)
+{
+  g_return_if_fail (ST_IS_THEME_CONTEXT (context));
+
+  if (color)
+    memcpy (color, &context->accent_color, sizeof (CoglColor));
+
+  if (fg_color)
+    memcpy (fg_color, &context->accent_fg_color, sizeof (CoglColor));
+}
+
 /**
  * st_theme_context_get_root_node:
  * @context: a #StThemeContext
index 165ce25f19228bc0cc88a576dc527fecdf67d5bf..3e4709e4ca9357ea39b6a07a809b66a104ef830d 100644 (file)
@@ -45,18 +45,22 @@ G_DECLARE_FINAL_TYPE (StThemeContext, st_theme_context,
 StThemeContext *st_theme_context_new           (void);
 StThemeContext *st_theme_context_get_for_stage (ClutterStage *stage);
 
-void                        st_theme_context_set_theme      (StThemeContext             *context,
-                                                             StTheme                    *theme);
-StTheme *                   st_theme_context_get_theme      (StThemeContext             *context);
+void                        st_theme_context_set_theme        (StThemeContext             *context,
+                                                               StTheme                    *theme);
+StTheme *                   st_theme_context_get_theme        (StThemeContext             *context);
 
-void                        st_theme_context_set_font       (StThemeContext             *context,
-                                                             const PangoFontDescription *font);
-const PangoFontDescription *st_theme_context_get_font       (StThemeContext             *context);
+void                        st_theme_context_set_font         (StThemeContext             *context,
+                                                               const PangoFontDescription *font);
+const PangoFontDescription *st_theme_context_get_font         (StThemeContext             *context);
 
-StThemeNode *               st_theme_context_get_root_node  (StThemeContext             *context);
+void                        st_theme_context_get_accent_color (StThemeContext             *context,
+                                                               CoglColor                  *color,
+                                                               CoglColor                  *fg_color);
 
-StThemeNode *               st_theme_context_intern_node    (StThemeContext             *context,
-                                                             StThemeNode                *node);
+StThemeNode *               st_theme_context_get_root_node    (StThemeContext             *context);
+
+StThemeNode *               st_theme_context_intern_node      (StThemeContext             *context,
+                                                               StThemeNode                *node);
 
 int st_theme_context_get_scale_factor (StThemeContext *context);